<template>
  <!-- 经销商 事业部、代码、名称  搜索 -->
  <div>
    <!-- 搜索 -->
    <TopFilter
      :list="topFilterInit"
      :cols="4"
      :collapse="collapse"
      labelWidth="90"
      @filterChange="changeHandle"
    ></TopFilter>
    <!-- table -->
    <FilterTable
      height="250"
      ref="listModal"
      :columns="columns"
      :selectionType="selectType"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      columnsRef='customerManage_clue_areaBossPush_dealerMadal_01'
      :onRowSelectChange="selectChange"
      :onColumnsChange="columns => this.columns = columns"
    ></FilterTable>
    <div class="dialogBottmView">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button @click="saveDialog" type="primary">{{submit}}</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { region } from '@/api/cms-common/region'; //行政区域
import { Notification } from 'element-ui';
import { getManageDealerListFilter } from '@/api/cms-api/customerManage/clue/areaBossOperation';
import { getRegion, getCommunity } from '@/api/cms-common/dealerdata/index';
export default {
  mixins: [dictionary, region],
  props: {
    submit: {
      type: String,
      default: '确定'
    },
    selectType: {
      type: String,
      default: 'multiple'
    }
  },
  data() {
    return {
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      fetchApi: getManageDealerListFilter,
      topFilterInit: this.topFilterInitFun(),
      columns: this.creatHeader(),
      fetchParams: null, //ipa 接口
      selectedRows: [] //选中经销商
    };
  },
  created(){
	console.error("这是个旧版本的经销商选择框，应使用【@/pages/cms-common/clue/dealerList】，参考【src\\pages\\cms-pages\\customerManage\\approvalManage\\approvalDetails\\infoBase.vue】");
  },
  methods: {
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'SELECT', label: '事业部', fieldName: 'majorManagerId', placeholder: '请选择', initialValue: '', itemList: this.createDictList('2566') },
        { type: 'INPUT', label: '经销商代码', fieldName: 'ownerCode', placeholder: '请选择', initialValue: '' },
        { type: 'INPUT', label: '经销商名称', fieldName: 'dealerName', placeholder: '请选择', initialValue: '' }
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '公司全称', dataIndex: 'companyName', sorter: true },
        { title: '经销商代码', dataIndex: 'ownerCode', sorter: true },
        { title: '经销商名称', dataIndex: 'dealerName', sorter: true },
        {
          title: '经销商类型',
          dataIndex: 'dealerType',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.dealerType, '2538')}</span>;
          }
        },
        {
          title: '经销商级别',
          dataIndex: 'shopLevel',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.shopLevel, '2540')}</span>;
          }
        },
        {
          title: '事业部',
          dataIndex: 'majorManagerId',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.majorManagerId, '2566')}</span>;
          }
        },
        {
          title: '省',
          dataIndex: 'provinceId',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createRegionText(props.row.provinceId)}</span>;
          }
        },
        {
          title: '市',
          dataIndex: 'cityId',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createRegionText(props.row.cityId)}</span>;
          }
        },
        {
          title: '县/区',
          dataIndex: 'districtId',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createRegionText(props.row.districtId)}</span>;
          }
        }
      ];
    },

    //选中
    selectChange(rows) {
      this.selectedRows = rows;
    },
    //保存
    saveDialog() {
      this.$emit('close', { visible: false, type: 'save', data: this.selectedRows });
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, type: 'close' });
    },
    //加载事业部数据
    async getDeptData() {
      const res = await getRegion({});
      if (res.resultCode === 200) {
        this.topFilterInit[0].itemList = res.data.map(x => ({ value: x.id, text: x.orgName }));
      }
    }
  },
  created() {
    //this.getDeptData();
  }
};
</script>

<style lang="less" scoped>
</style>
